{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thread-106 start to run Thread-118 start to run \n",
      "Thread-158 start to run \n",
      "Thread-166 start to run \n",
      "Thread-137 start to run \n",
      "Thread-179 start to run \n",
      "Thread-182 start to run \n",
      "Thread-128 start to run \n",
      "Thread-155 start to run \n",
      "Thread-141 start to run Thread-143 start to run Thread-130 start to run Thread-175 start to run \n",
      "Thread-170 start to run \n",
      "Thread-122 start to run \n",
      "Thread-107 start to run \n",
      "Thread-151 start to run Thread-129 start to run \n",
      "Thread-119 start to run \n",
      "Thread-132 start to run Thread-195 start to run \n",
      "\n",
      "\n",
      "\n",
      "Thread-174 start to run Thread-203 start to run Thread-138 start to run Thread-156 start to run \n",
      "Thread-140 start to run \n",
      "Thread-173 start to run Thread-133 start to run \n",
      "Thread-121 start to run \n",
      "Thread-134 start to run Thread-125 start to run \n",
      "Thread-124 start to run \n",
      "Thread-171 start to run \n",
      "Thread-172 start to run \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Thread-176 start to run \n",
      "Thread-181 start to run Thread-198 start to run Thread-147 start to run \n",
      "Thread-205 start to run \n",
      "Thread-165 start to run \n",
      "Thread-177 start to run \n",
      "\n",
      "Thread-114 start to run \n",
      "\n",
      "Thread-127 start to run \n",
      "Thread-139 start to run \n",
      "Thread-194 start to run \n",
      "Thread-145 start to run \n",
      "\n",
      "Thread-108 start to run \n",
      "Thread-163 start to run \n",
      "Thread-200 start to run \n",
      "Thread-187 start to run \n",
      "Thread-199 start to run \n",
      "Thread-123 start to run \n",
      "\n",
      "Thread-157 start to run \n",
      "Thread-191 start to run \n",
      "Thread-110 start to run \n",
      "Thread-150 start to run \n",
      "Thread-197 start to run \n",
      "Thread-193 start to run \n",
      "Thread-148 start to run \n",
      "Thread-109 start to run \n",
      "Thread-161 start to run \n",
      "\n",
      "Thread-152 start to run \n",
      "Thread-201 start to run \n",
      "Thread-117 start to run Thread-188 start to run \n",
      "Thread-183 start to run \n",
      "Thread-196 start to run Thread-126 start to run \n",
      "Thread-131 start to run \n",
      "Thread-186 start to run \n",
      "\n",
      "Thread-169 start to run \n",
      "Thread-204 start to run \n",
      "Thread-115 start to run \n",
      "Thread-189 start to run \n",
      "Thread-146 start to run \n",
      "Thread-164 start to run \n",
      "Thread-192 start to run \n",
      "Thread-190 start to run \n",
      "Thread-120 start to run \n",
      "Thread-136 start to run \n",
      "\n",
      "Thread-149 start to run \n",
      "Thread-144 start to run \n",
      "Thread-185 start to run \n",
      "Thread-178 start to run \n",
      "Thread-167 start to run \n",
      "Thread-202 start to run \n",
      "Thread-160 start to run \n",
      "Thread-168 start to run \n",
      "Thread-184 start to run \n",
      "Thread-162 start to run \n",
      "Thread-154 start to run \n",
      "Thread-111 start to run \n",
      "Thread-113 start to run \n",
      "Thread-142 start to run \n",
      "\n",
      "Thread-159 start to run \n",
      "Thread-153 start to run \n",
      "Thread-112 start to run \n",
      "Thread-116 start to run \n",
      "Thread-135 start to run Thread-180 start to run \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from threading import Thread,current_thread,Lock\n",
    "import os,time\n",
    "def task():\n",
    "    time.sleep(3)\n",
    "    print('%s start to run '%current_thread().getName())\n",
    "    global n\n",
    "    lock.acquire()\n",
    "    temp=n\n",
    "    time.sleep(0.5)\n",
    "    n=temp-1\n",
    "    lock.release()\n",
    "if __name__=='__main__':\n",
    "    n=100\n",
    "    lock=Lock()\n",
    "    l=[]\n",
    "    start_time=time.time()\n",
    "    for i in range(100):\n",
    "        t=Thread(target=task)\n",
    "        l.append(t)\n",
    "        t.start()\n",
    "    for t in l:\n",
    "        t.join()\n",
    "    stop_time=time.time()\n",
    "    print('主:%s n:%s'%(stop_time-start_time,n))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "24\n",
      "25\n",
      "26\n",
      "27\n",
      "28\n",
      "29\n",
      "30\n",
      "31\n",
      "32\n",
      "33\n",
      "34\n",
      "35\n",
      "36\n",
      "37\n",
      "38\n",
      "39\n",
      "40\n",
      "41\n",
      "42\n",
      "43\n",
      "44\n",
      "45\n",
      "46\n",
      "47\n",
      "48\n",
      "49\n",
      "50\n",
      "51\n",
      "52\n",
      "53\n",
      "54\n",
      "55\n",
      "56\n",
      "57\n",
      "58\n",
      "59\n",
      "60\n",
      "61\n",
      "62\n",
      "63\n",
      "64\n",
      "65\n",
      "66\n",
      "67\n",
      "68\n",
      "69\n",
      "70\n",
      "71\n",
      "72\n",
      "73\n",
      "74\n",
      "75\n",
      "76\n",
      "77\n",
      "78\n",
      "79\n",
      "80\n",
      "81\n",
      "82\n",
      "83\n",
      "84\n",
      "85\n",
      "86\n",
      "87\n",
      "88\n",
      "89\n",
      "90\n",
      "91\n",
      "92\n",
      "93\n",
      "94\n",
      "95\n",
      "96\n",
      "97\n",
      "98\n",
      "99\n"
     ]
    }
   ],
   "source": [
    "for i in range(100):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (<ipython-input-7-0c9f44c08998>, line 20)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-7-0c9f44c08998>\"\u001b[1;36m, line \u001b[1;32m20\u001b[0m\n\u001b[1;33m    print('主:%s n:%s'%(stop_time-start_time)\u001b[0m\n\u001b[1;37m                                            ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "from threading import Thread,current_thread,Lock\n",
    "\n",
    "import os,time\n",
    "def task():\n",
    "    time.sleep(3)\n",
    "    print('%s start to run '%current_thread().getName())\n",
    "    global n\n",
    "    temp=n\n",
    "    time.sleep(0.5)\n",
    "    n=temp-1\n",
    "if __name__=='__main__':\n",
    "    n=100\n",
    "    lock=Lock()\n",
    "    start_time=time.time()\n",
    "    for i in range(100):\n",
    "        t=Thread(target=task)\n",
    "        t.start()\n",
    "        t.join()\n",
    "    stop_time=time.time()\n",
    "    print('主:%s n:%s'%(stop_time-start_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "li=[1,2,3,4,1]\n",
    "res=random.shuffle(li)\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('dfjgldf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
